package com.dhp.Exception;

import com.dhp.Common.ErrorCode;
import com.dhp.Common.Result;
import com.dhp.Common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(exception.class)
    public Result handler(exception ex){
        log.info(ex.getMessage());
        return ResultUtils.error(ex.getCode() , ex.getMessage() , ex.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result LocalHandler(RuntimeException e){
        log.info(e.getMessage());
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }
}
